using System;
using System.Drawing;
using System.Windows.Forms;

// Step II for using SystemTrayNotifyIcon class in your project
using SystemTrayNotification;

namespace SystemTrayIcon
{
	 /// <summary>
	 /// Summary description for MainForm.
	 /// </summary>
	 public class MainForm : System.Windows.Forms.Form
	 {
		  /// <summary>
		  /// Required designer variable.
		  /// </summary>
		  private System.ComponentModel.Container components = null;

		  public MainForm() {

				//
				// Required for Windows Form Designer support
				//
				InitializeComponent();

				//
				// TODO: Add any constructor code after InitializeComponent call
				//
				NumberOfAnimations.SelectedIndex = 0;
				timeInterval.SelectedIndex = 0;
				ShowIcon.Enabled = false;
				StopAnimation.Enabled = false;
				mailto.Links.Add( 8 , 21 , "mailto:bilijeans@hotmail.com" );

				m_SysTrayNotify = new SystemTrayNotification.SystemTrayNotifyIcon( this , true , "I am getting Notifications..." , new System.Drawing.Icon( "..\\..\\Default Icon\\PakFlag.ico" ) );	// Step III for using SystemTrayNotifyIcon class in your project
				m_SysTrayNotify.OnStatusChanged += new SystemTrayNotifyIcon.StatusChanged( SystemTrayNotificationHandler );	// Setting Event Handler

				iconArray = new Icon[8];
				for( int i = 1 ; i <= iconArray.Length ; i++ ) {
					 try {
						  iconArray[i - 1] = new Icon( "..\\..\\Animation Icons\\icon" + i + ".ico" );
					 }
					 catch( Exception e ) {
						  MessageBox.Show( e.Message , "Error" , MessageBoxButtons.OK , MessageBoxIcon.Error );
					 }
				}
				m_SysTrayNotify.LoadIcons( iconArray );
		  }

		  /// <summary>
		  /// Clean up any resources being used.
		  /// </summary>
		  protected override void Dispose( bool disposing ) {
				m_SysTrayNotify.Dispose();	// (Last but Not the Least) Step for using SystemTrayNotifyIcon class in your project
				if( disposing ) {
					 if( components != null ) {
						  components.Dispose();
					 }
				}
				base.Dispose( disposing );
		  }

		  #region Windows Form Designer generated code

		  /// <summary>
		  /// Required method for Designer support - do not modify
		  /// the contents of this method with the code editor.
		  /// </summary>
		  private void InitializeComponent() {
				System.Resources.ResourceManager resources = new System.Resources.ResourceManager( typeof( MainForm ) );
				this.Explaination = new System.Windows.Forms.Label();
				this.pictureBox1 = new System.Windows.Forms.PictureBox();
				this.label1 = new System.Windows.Forms.Label();
				this.pictureBox2 = new System.Windows.Forms.PictureBox();
				this.pictureBox3 = new System.Windows.Forms.PictureBox();
				this.pictureBox4 = new System.Windows.Forms.PictureBox();
				this.pictureBox5 = new System.Windows.Forms.PictureBox();
				this.pictureBox6 = new System.Windows.Forms.PictureBox();
				this.pictureBox7 = new System.Windows.Forms.PictureBox();
				this.pictureBox8 = new System.Windows.Forms.PictureBox();
				this.pictureBox9 = new System.Windows.Forms.PictureBox();
				this.Animate = new System.Windows.Forms.Button();
				this.label2 = new System.Windows.Forms.Label();
				this.NumberOfAnimations = new System.Windows.Forms.ComboBox();
				this.timeInterval = new System.Windows.Forms.ComboBox();
				this.label3 = new System.Windows.Forms.Label();
				this.StopAnimation = new System.Windows.Forms.Button();
				this.label4 = new System.Windows.Forms.Label();
				this.HideIcon = new System.Windows.Forms.Button();
				this.ShowIcon = new System.Windows.Forms.Button();
				this.label5 = new System.Windows.Forms.Label();
				this.eventList = new System.Windows.Forms.ListBox();
				this.mailto = new System.Windows.Forms.LinkLabel();
				this.pictureBox10 = new System.Windows.Forms.PictureBox();
				this.SuspendLayout();

				//
				// Explaination
				//
				this.Explaination.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.Explaination.Location = new System.Drawing.Point( 8 , 8 );
				this.Explaination.Name = "Explaination";
				this.Explaination.Size = new System.Drawing.Size( 536 , 16 );
				this.Explaination.TabIndex = 0;
				this.Explaination.Text = "1. This class will only allow icons of size 16x16 to be shown in System Tray e.g." +
					" PakFlag.ico (size 16x16)";

				//
				// pictureBox1
				//
				this.pictureBox1.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox1.Image" ) ) );
				this.pictureBox1.Location = new System.Drawing.Point( 528 , 8 );
				this.pictureBox1.Name = "pictureBox1";
				this.pictureBox1.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox1.TabIndex = 1;
				this.pictureBox1.TabStop = false;

				//
				// label1
				//
				this.label1.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.label1.Location = new System.Drawing.Point( 8 , 24 );
				this.label1.Name = "label1";
				this.label1.Size = new System.Drawing.Size( 536 , 32 );
				this.label1.TabIndex = 2;
				this.label1.Text = "2. I am using the below given set of Icons for Animation. You can use your own se" +
					"t of icons and the number of icons is upto your choice.";

				//
				// pictureBox2
				//
				this.pictureBox2.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox2.Image" ) ) );
				this.pictureBox2.Location = new System.Drawing.Point( 22 , 62 );
				this.pictureBox2.Name = "pictureBox2";
				this.pictureBox2.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox2.TabIndex = 3;
				this.pictureBox2.TabStop = false;

				//
				// pictureBox3
				//
				this.pictureBox3.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox3.Image" ) ) );
				this.pictureBox3.Location = new System.Drawing.Point( 38 , 62 );
				this.pictureBox3.Name = "pictureBox3";
				this.pictureBox3.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox3.TabIndex = 4;
				this.pictureBox3.TabStop = false;

				//
				// pictureBox4
				//
				this.pictureBox4.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox4.Image" ) ) );
				this.pictureBox4.Location = new System.Drawing.Point( 54 , 62 );
				this.pictureBox4.Name = "pictureBox4";
				this.pictureBox4.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox4.TabIndex = 5;
				this.pictureBox4.TabStop = false;

				//
				// pictureBox5
				//
				this.pictureBox5.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox5.Image" ) ) );
				this.pictureBox5.Location = new System.Drawing.Point( 70 , 62 );
				this.pictureBox5.Name = "pictureBox5";
				this.pictureBox5.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox5.TabIndex = 6;
				this.pictureBox5.TabStop = false;

				//
				// pictureBox6
				//
				this.pictureBox6.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox6.Image" ) ) );
				this.pictureBox6.Location = new System.Drawing.Point( 86 , 62 );
				this.pictureBox6.Name = "pictureBox6";
				this.pictureBox6.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox6.TabIndex = 7;
				this.pictureBox6.TabStop = false;

				//
				// pictureBox7
				//
				this.pictureBox7.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox7.Image" ) ) );
				this.pictureBox7.Location = new System.Drawing.Point( 102 , 62 );
				this.pictureBox7.Name = "pictureBox7";
				this.pictureBox7.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox7.TabIndex = 8;
				this.pictureBox7.TabStop = false;

				//
				// pictureBox8
				//
				this.pictureBox8.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox8.Image" ) ) );
				this.pictureBox8.Location = new System.Drawing.Point( 118 , 62 );
				this.pictureBox8.Name = "pictureBox8";
				this.pictureBox8.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox8.TabIndex = 9;
				this.pictureBox8.TabStop = false;

				//
				// pictureBox9
				//
				this.pictureBox9.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox9.Image" ) ) );
				this.pictureBox9.Location = new System.Drawing.Point( 134 , 62 );
				this.pictureBox9.Name = "pictureBox9";
				this.pictureBox9.Size = new System.Drawing.Size( 16 , 16 );
				this.pictureBox9.TabIndex = 10;
				this.pictureBox9.TabStop = false;

				//
				// Animate
				//
				this.Animate.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.Animate.Location = new System.Drawing.Point( 462 , 62 );
				this.Animate.Name = "Animate";
				this.Animate.Size = new System.Drawing.Size( 82 , 22 );
				this.Animate.TabIndex = 11;
				this.Animate.Text = "Animate Icon";
				this.Animate.Click += new System.EventHandler( this.Animate_Click );

				//
				// label2
				//
				this.label2.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.label2.Location = new System.Drawing.Point( 234 , 64 );
				this.label2.Name = "label2";
				this.label2.Size = new System.Drawing.Size( 148 , 16 );
				this.label2.TabIndex = 13;
				this.label2.Text = "Number of times to animate:";

				//
				// NumberOfAnimations
				//
				this.NumberOfAnimations.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
				this.NumberOfAnimations.Font = new System.Drawing.Font( "Microsoft Sans Serif" , 8.25F , System.Drawing.FontStyle.Bold , System.Drawing.GraphicsUnit.Point , ( (System.Byte) ( 0 ) ) );
				this.NumberOfAnimations.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.NumberOfAnimations.Items.AddRange( new object[] {
																	"1",
																	"2",
																	"3",
																	"4",
																	"5",
																	"Infinite"} );
				this.NumberOfAnimations.Location = new System.Drawing.Point( 384 , 62 );
				this.NumberOfAnimations.Name = "NumberOfAnimations";
				this.NumberOfAnimations.Size = new System.Drawing.Size( 76 , 21 );
				this.NumberOfAnimations.TabIndex = 14;

				//
				// timeInterval
				//
				this.timeInterval.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
				this.timeInterval.Font = new System.Drawing.Font( "Microsoft Sans Serif" , 8.25F , System.Drawing.FontStyle.Bold , System.Drawing.GraphicsUnit.Point , ( (System.Byte) ( 0 ) ) );
				this.timeInterval.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.timeInterval.Items.AddRange( new object[] {
															  "100",
															  "200",
															  "300",
															  "400",
															  "500",
															  "600",
															  "700",
															  "800",
															  "900",
															  "1000"} );
				this.timeInterval.Location = new System.Drawing.Point( 384 , 84 );
				this.timeInterval.Name = "timeInterval";
				this.timeInterval.Size = new System.Drawing.Size( 76 , 21 );
				this.timeInterval.TabIndex = 16;

				//
				// label3
				//
				this.label3.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.label3.Location = new System.Drawing.Point( 308 , 86 );
				this.label3.Name = "label3";
				this.label3.Size = new System.Drawing.Size( 74 , 16 );
				this.label3.TabIndex = 15;
				this.label3.Text = "Time Interval:";

				//
				// StopAnimation
				//
				this.StopAnimation.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.StopAnimation.Location = new System.Drawing.Point( 462 , 86 );
				this.StopAnimation.Name = "StopAnimation";
				this.StopAnimation.Size = new System.Drawing.Size( 82 , 20 );
				this.StopAnimation.TabIndex = 17;
				this.StopAnimation.Text = "Stop";
				this.StopAnimation.Click += new System.EventHandler( this.StopAnimation_Click );

				//
				// label4
				//
				this.label4.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.label4.Location = new System.Drawing.Point( 8 , 108 );
				this.label4.Name = "label4";
				this.label4.Size = new System.Drawing.Size( 536 , 30 );
				this.label4.TabIndex = 18;
				this.label4.Text = "3. We can Hide and Show System Tray Icon just by setting \"Visibility\" property fa" +
					"lse or true. See what is happening behind the below given buttons.";

				//
				// HideIcon
				//
				this.HideIcon.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.HideIcon.Location = new System.Drawing.Point( 180 , 140 );
				this.HideIcon.Name = "HideIcon";
				this.HideIcon.Size = new System.Drawing.Size( 98 , 20 );
				this.HideIcon.TabIndex = 19;
				this.HideIcon.Text = "Hide Icon";
				this.HideIcon.Click += new System.EventHandler( this.HideIcon_Click );

				//
				// ShowIcon
				//
				this.ShowIcon.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.ShowIcon.Location = new System.Drawing.Point( 280 , 140 );
				this.ShowIcon.Name = "ShowIcon";
				this.ShowIcon.Size = new System.Drawing.Size( 98 , 20 );
				this.ShowIcon.TabIndex = 20;
				this.ShowIcon.Text = "Show Icon";
				this.ShowIcon.Click += new System.EventHandler( this.ShowIcon_Click );

				//
				// label5
				//
				this.label5.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.label5.Location = new System.Drawing.Point( 8 , 170 );
				this.label5.Name = "label5";
				this.label5.Size = new System.Drawing.Size( 538 , 40 );
				this.label5.TabIndex = 21;
				this.label5.Text = @"4. The best part of this program is the event generation mechanism, which will generate an event of specific type according to the changed state of SystemTrayNotifyIcon. The ListBox shown below is updated every time an event is generated in SystemTrayNotifyIcon class.";

				//
				// eventList
				//
				this.eventList.ForeColor = System.Drawing.Color.DarkOliveGreen;
				this.eventList.Location = new System.Drawing.Point( 8 , 212 );
				this.eventList.Name = "eventList";
				this.eventList.Size = new System.Drawing.Size( 538 , 69 );
				this.eventList.TabIndex = 22;

				//
				// mailto
				//
				this.mailto.Location = new System.Drawing.Point( 354 , 292 );
				this.mailto.Name = "mailto";
				this.mailto.Size = new System.Drawing.Size( 158 , 16 );
				this.mailto.TabIndex = 23;
				this.mailto.TabStop = true;
				this.mailto.Text = "mailto: bilijeans@hotmail.com";
				this.mailto.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler( this.mailto_LinkClicked );

				//
				// pictureBox10
				//
				this.pictureBox10.Image = ( (System.Drawing.Bitmap) ( resources.GetObject( "pictureBox10.Image" ) ) );
				this.pictureBox10.Location = new System.Drawing.Point( 514 , 284 );
				this.pictureBox10.Name = "pictureBox10";
				this.pictureBox10.Size = new System.Drawing.Size( 32 , 30 );
				this.pictureBox10.TabIndex = 24;
				this.pictureBox10.TabStop = false;

				//
				// MainForm
				//
				this.AutoScaleBaseSize = new System.Drawing.Size( 5 , 13 );
				this.ClientSize = new System.Drawing.Size( 562 , 321 );
				this.Controls.AddRange( new System.Windows.Forms.Control[] {
																		  this.pictureBox10,
																		  this.mailto,
																		  this.eventList,
																		  this.label5,
																		  this.ShowIcon,
																		  this.HideIcon,
																		  this.label4,
																		  this.StopAnimation,
																		  this.timeInterval,
																		  this.label3,
																		  this.NumberOfAnimations,
																		  this.label2,
																		  this.Animate,
																		  this.pictureBox9,
																		  this.pictureBox8,
																		  this.pictureBox7,
																		  this.pictureBox6,
																		  this.pictureBox5,
																		  this.pictureBox4,
																		  this.pictureBox3,
																		  this.pictureBox2,
																		  this.label1,
																		  this.pictureBox1,
																		  this.Explaination} );
				this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
				this.MaximizeBox = false;
				this.Name = "MainForm";
				this.ShowInTaskbar = false;
				this.Text = "SystemTrayIcon";
				this.ResumeLayout( false );
		  }

		  #endregion Windows Form Designer generated code

		  /// <summary>
		  /// The main entry point for the application.
		  /// </summary>
		  [STAThread]
		  private static void Main() {
				Application.Run( new MainForm() );
		  }

		  private System.Windows.Forms.Label Explaination;
		  private System.Windows.Forms.Label label1;
		  private System.Windows.Forms.Label label2;
		  private System.Windows.Forms.Label label3;
		  private System.Windows.Forms.Label label4;
		  private System.Windows.Forms.PictureBox pictureBox1;
		  private System.Windows.Forms.PictureBox pictureBox2;
		  private System.Windows.Forms.PictureBox pictureBox3;
		  private System.Windows.Forms.PictureBox pictureBox4;
		  private System.Windows.Forms.PictureBox pictureBox5;
		  private System.Windows.Forms.PictureBox pictureBox6;
		  private System.Windows.Forms.PictureBox pictureBox7;
		  private System.Windows.Forms.PictureBox pictureBox8;
		  private System.Windows.Forms.PictureBox pictureBox9;
		  private System.Windows.Forms.PictureBox pictureBox10;
		  private System.Windows.Forms.Button Animate;
		  private System.Windows.Forms.ComboBox NumberOfAnimations;
		  private System.Drawing.Icon[] iconArray;
		  private System.Windows.Forms.ComboBox timeInterval;
		  private System.Windows.Forms.Button StopAnimation;
		  private System.Windows.Forms.Button HideIcon;
		  private System.Windows.Forms.Button ShowIcon;
		  private System.Windows.Forms.Label label5;
		  private System.Windows.Forms.ListBox eventList;
		  private System.Windows.Forms.LinkLabel mailto;

		  // Step III for using SystemTrayNotifyIcon class in your project
		  private SystemTrayNotifyIcon m_SysTrayNotify;

		  private void Animate_Click( object sender , System.EventArgs e ) {
				switch( NumberOfAnimations.Text ) {
					 case "1":
						  m_SysTrayNotify.Animate( 1 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 case "2":
						  m_SysTrayNotify.Animate( 2 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 case "3":
						  m_SysTrayNotify.Animate( 3 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 case "4":
						  m_SysTrayNotify.Animate( 4 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 case "5":
						  m_SysTrayNotify.Animate( 5 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 case "Infinite":
						  m_SysTrayNotify.Animate( -1 , System.Convert.ToInt32( timeInterval.Text ) );
						  break;

					 default:
						  MessageBox.Show( "You must select a valid entry from the combo box before pressing this button..." , "Invalid Input..." , System.Windows.Forms.MessageBoxButtons.OK , System.Windows.Forms.MessageBoxIcon.Warning );
						  break;
				}
		  }

		  private void StopAnimation_Click( object sender , System.EventArgs e ) {
				m_SysTrayNotify.KeepAnimationAlive = false;
		  }

		  private void HideIcon_Click( object sender , System.EventArgs e ) {
				m_SysTrayNotify.Visibility = false;
		  }

		  private void ShowIcon_Click( object sender , System.EventArgs e ) {
				m_SysTrayNotify.Visibility = true;
		  }

		  /// <summary>
		  /// Event Handler for SystemTrayNotifyIcon
		  /// </summary>
		  /// <param name="sender">object</param>
		  /// <param name="e">SystemTrayNotificationEventArgs</param>
		  protected void SystemTrayNotificationHandler( object sender , SystemTrayNotificationEventArgs e ) {
				switch( e.State ) {
					 case SystemTrayNotification.SystemTrayNotificationEventType.Hiding:
						  ShowInTaskbar = true;
						  HideIcon.Enabled = false;
						  ShowIcon.Enabled = true;
						  StopAnimation.Enabled = false;
						  Animate.Enabled = false;
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.Hiding" );
						  break;

					 case SystemTrayNotification.SystemTrayNotificationEventType.Showing:
						  ShowInTaskbar = false;
						  HideIcon.Enabled = true;
						  ShowIcon.Enabled = false;
						  StopAnimation.Enabled = true;
						  Animate.Enabled = true;
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.Showing" );
						  break;

					 case SystemTrayNotification.SystemTrayNotificationEventType.StartingAnimation:
						  StopAnimation.Enabled = true;
						  Animate.Enabled = false;
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.StartingAnimation" );
						  break;

					 case SystemTrayNotification.SystemTrayNotificationEventType.StopingAnimation:
						  StopAnimation.Enabled = false;
						  Animate.Enabled = true;
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.StopingAnimation" );
						  break;

					 case SystemTrayNotification.SystemTrayNotificationEventType.IconChanged:
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.IconChanged" );
						  break;

					 case SystemTrayNotification.SystemTrayNotificationEventType.Disposing:
						  eventList.Items.Add( "SystemTrayNotification.SystemTrayNotificationEventType.Disposing" );
						  break;

					 default:
						  break;
				}
				eventList.SelectedIndex = eventList.Items.Count - 1;
		  }

		  private void mailto_LinkClicked( object sender , System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) {
				System.Diagnostics.Process.Start( e.Link.LinkData.ToString() );
		  }
	 }
}